﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace TinyCinema.UI.UserControls
{
    /// <summary>
    /// Interaction logic for Setting.xaml
    /// </summary>
    public partial class Setting : UserControl
    {
        public Setting()
        {
            InitializeComponent();
        }
        bool isExpanded = false;
        private void btnSetting_Click(object sender, RoutedEventArgs e)
        {
            if (!isExpanded)
            {
                ((Storyboard)FindResource("triggerExpand")).Begin();
                isExpanded = true;                
                grdRoot.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
                Panel.SetZIndex(this, Panel.GetZIndex(this) + 2);
            }
            else ViewUnexpand();
        }
        private void UserControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                ViewUnexpand();
            }
        }      

        private void UserControl_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (!IsEnabled) IsEnabled = true;
            ViewUnexpand();
        }
        private void ViewUnexpand()
        {
            if (isExpanded)
            {
                ((Storyboard)FindResource("triggerExpanded")).Begin();
                isExpanded = false;
                grdRoot.Background = null;
                Panel.SetZIndex(this, 0);
            }
        }

        private void grdRoot_MouseDown(object sender, MouseButtonEventArgs e)
        {
            ViewUnexpand();
        }

    }
}
